import{ut as e}from"./B603vO-13smUKN.js";import{t}from"./CvEJN-vi4hXmWG.js";import{D as n,E as r,On as i,_ as a,b as o,g as s,k as c,mt as l,tr as u,vn as d,y as f}from"./CIxmKYxc4tZcJF.js";import"./DcwiUW8R1GKRvl.js";import{t as p}from"./DhtdLMWurC5tl.js";import{a as m,c as h,n as g,o as _,s as v,t as y}from"./BVvRFS7mRz5uC.js";import{a as b,o as x}from"./BbxvatETxeTHf.js";import{t as S}from"./qOf9hsdh3aD96J.js";import"./C3Xax3Tz4BagVD.js";import{t as C}from"./DlpkIUzkqr8f6.js";var w={class:`app-settings-storage`},T={key:0,class:`notice`},E={key:1,class:`folder-attached`},D={key:0,class:`status ok`},O={key:1,class:`status err`},k={key:2,class:`status`},A={class:`hint`},j={key:2},M={key:3,class:`error`},N={key:4,class:`warning`},P={class:`hint`},F=c({__name:`app-settings-storage`,setup(c){let F=e(`settings-storage`),I=s(()=>g()),L=s(()=>I.value?.remotes.value??[]),R=s(()=>L.value.find(e=>e.name===y)),z=d(``),B=d(``),V=d(!1),H=typeof window<`u`&&`showDirectoryPicker`in window;async function U(e,t){if(!await _(e,`readwrite`)){V.value=!0,B.value=e.name;return}V.value=!1,B.value=e.name;let n=x.workspace?.id;!n||!I.value||(await I.value.attachFolder(y,e),t&&await h(n,e))}async function W(){z.value=``;try{let e=window.showDirectoryPicker;if(!e)throw Error(`FileSystem Access API not available in this browser`);let n=await e({mode:`readwrite`});if(!await _(n,`readwrite`)){V.value=!0,B.value=n.name;return}V.value=!1;let r=x.workspace?.id,i=await g().openFromFolder(n);B.value=n.name,t({title:b(`settings.storage.attached`),message:n.name}),i.wid!==r&&await C.workspace(i.wid)}catch(e){if(e.name===`AbortError`)return;z.value=e.message,F.warn(`pick folder failed`,e)}}function G(){S(b(`settings.storage.downloadingAssets`),async()=>{let e=await g().fetchAllAssets(y);F(`fetchAllAssets copied=${e}`),t({title:b(`settings.storage.downloadDone`),message:String(e)})})}function K(){S(b(`settings.storage.duplicateRunning`),async()=>{let e=x.workspace?.id,n=b(`settings.storage.duplicateCopyName`,{title:e&&x.workspaces[e]?.title?.trim()||`Doocs`}),r=await g().duplicateWorkspace(n);F(`duplicated ${e} -> ${r.wid}`,r.stats),t({title:b(`settings.storage.duplicateDone`),message:b(`settings.storage.duplicateStats`,{records:r.stats.records,assets:r.stats.assetsCopied})}),await C.workspace(r.wid)})}async function q(){z.value=``,V.value=!1,B.value=``;let e=x.workspace?.id;I.value&&(await I.value.detachRemote(y),e&&await m(e))}return(async()=>{let e=x.workspace?.id;if(!e)return;let t=await v(e).catch(()=>null);t&&await U(t,!1)})(),(e,t)=>(l(),o(`div`,w,[a(`h2`,null,u(i(b)(`settings.storage.title`)),1),i(H)?R.value?(l(),o(`div`,E,[a(`p`,null,[a(`strong`,null,u(B.value),1),R.value.ready?(l(),o(`span`,D,`● ready`)):R.value.error?(l(),o(`span`,O,`● `+u(R.value.error),1)):(l(),o(`span`,k,`● syncing…`))]),a(`p`,A,u(i(b)(`settings.storage.lazyAssetsHint`)),1),n(i(p),{title:i(b)(`settings.storage.downloadAll`),onClick:G},null,8,[`title`]),n(i(p),{title:i(b)(`settings.storage.detach`),onClick:q},null,8,[`title`])])):(l(),o(`div`,j,[n(i(p),{title:i(b)(`settings.storage.pickFolder`),onClick:W},null,8,[`title`])])):(l(),o(`div`,T,u(i(b)(`settings.storage.needsChrome`)),1)),z.value?(l(),o(`p`,M,u(z.value),1)):f(``,!0),V.value?(l(),o(`p`,N,[r(u(i(b)(`settings.storage.permissionNeeded`))+` `,1),a(`code`,null,u(B.value),1)])):f(``,!0),a(`h2`,null,u(i(b)(`settings.storage.duplicateTitle`)),1),a(`p`,P,u(i(b)(`settings.storage.duplicateDesc`)),1),n(i(p),{title:i(b)(`settings.storage.duplicateAction`),onClick:K},null,8,[`title`])]))}});export{F as default};